﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Core;
using Tanmia.Basis.ViewModel;
using Tanmia.Domain;
using System.ComponentModel;
using System.Windows.Data;

namespace Tanmia.Windows.DiscriminatedItemScenario
{
    public class DiscriminatedItemViewModel : BaseViewModel<DiscriminatedItem>
    {
        public ICollectionView Items { get; private set; }
        public ICollectionView Colors { get; private set; }
        public ICollectionView Manufacturers { get; private set; }
        public ICollectionView Units { get; private set; }


        private ItemDomain ItemDomainObj = new ItemDomain();
        private ColorDomain ColorDomainObj = new ColorDomain();
        private PersonDomain PersonDomainObj = new PersonDomain();
        private UnitDomain UnitDomainObj = new UnitDomain();

        public DiscriminatedItemViewModel()
            : base(new DiscriminatedItemDomain())
        {
            UpdateItems();
            UpdateColors(null);
            UpdateManufacturers();
            UpdateUnits();
        }

        public void UpdateItems()
        {
            Items = CollectionViewSource.GetDefaultView(ItemDomainObj.GetsWithSelect());
            RaisePropertyChanged("Items");
        }

        public void UpdateColors(ItemCategory itemCategory)
        {
            if (itemCategory != null)
                Colors = CollectionViewSource.GetDefaultView(ColorDomainObj.GetsByCategoryWithEasyAdd(itemCategory));
            else
                Colors = null;

            RaisePropertyChanged("Colors");
        }

        public void UpdateManufacturers()
        {
            Manufacturers = CollectionViewSource.GetDefaultView(PersonDomainObj.GetsByTypeWithEasyAdd(PersonTypeEnum.Manufacturer));
            RaisePropertyChanged("Manufacturers");
        }

        public void UpdateUnits()
        {
            Units = CollectionViewSource.GetDefaultView(UnitDomainObj.GetsWithSelect());
            RaisePropertyChanged("Units");
        }
    }
}
